﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace HugeFlow.CommandPattern.Commands
{
    /// <summary>
    ///  class for InstantCommand and CommandParameter's binding
    /// </summary>
    internal class InstantCommandBinder : CommandBinderBase
    {
        #region InstantCommand

        /// <summary> 
        /// Gets or sets the InstantCommand possible Value of the InstantCommand<object> object.
        /// </summary> 
        public InstantCommand<object> InstantCommand
        {
            get { return (InstantCommand<object>)GetValue(InstantCommandProperty); }
            set { SetValue(InstantCommandProperty, value); }
        }

        /// <summary> 
        /// Identifies the InstantCommand dependency property.
        /// </summary> 
        public static readonly DependencyProperty InstantCommandProperty =
                    DependencyProperty.Register(
                          "InstantCommand",
                          typeof(InstantCommand<object>),
                          typeof(InstantCommandBinder),
                          null);
        #endregion InstantCommand

        #region ICommand Members
        public override bool CanExecute(object parameter)
        {
            if (InstantCommand == null)
                return false;
            else
                return true;
        }

        public override void Execute(object parameter)
        {
            if (parameter == null)
                parameter = InstantCommandParameter;

            InstantCommand.Invoke(parameter);
        }
        #endregion
    }
}
